<template>
  <div class="content-wrap content-container" v-loading="loading">
    <!-- 搜索区域 -->
    <el-form class="search-wrap" v-model="searchFormData">
      <el-form-item class="search-wrap-item" label="标题关键字：" prop="projectTitle">
        <el-input width="160px" placeholder="请输入标题关键字" v-model="searchFormData.projectTitle" clearable
          @input="getAllRequirements"></el-input>
      </el-form-item>
      <el-form-item class="search-wrap-item" label="开始时间：" prop="beginTime">
        <el-date-picker style="width: 240px" :value-on-clear="null" type="date" unlink-panels placeholder="选择开始时间"
          v-model="searchFormData.beginTime" @change="getAllRequirements" />
      </el-form-item>

      <el-form-item class="search-wrap-item" label="结束时间：" prop="endTime">
        <el-date-picker style="width: 240px" :value-on-clear="null" type="date" unlink-panels placeholder="选择结束时间"
          v-model="searchFormData.endTime" @change="getAllRequirements" />
      </el-form-item>
      <el-form-item class="search-wrap-item" label="需求状态：" prop="requirementStatus">
        <el-select class="search-select" placeholder="全部" v-model="searchFormData.requirementStatus" clearable
          filterable @change="getAllRequirements">
          <el-option v-for="item in requirementStatuss" :key="item.id" :label="item.typeName" :value="item.id" />
        </el-select>
      </el-form-item>
    </el-form>

    <!-- 待上线评审需求列表区域 -->
    <div class="card-wrap-table">
      <el-table :data="allRequirements" border style="width: 100%; height: 100%;font-size: 12px;">
        <el-table-column fixed type="index" label="序号" width="60" align="center"></el-table-column>
        <el-table-column label="需求名称" prop="itemRequirementName" min-width="300" show-overflow-tooltip>
          <template #="{ row }">
            <p class="table-requirement-name" @click="handleRowClick(row.itemRequirementId)">{{ row.itemRequirementName
            }}</p>
          </template>
        </el-table-column>
        <el-table-column label="技术负责人" prop="requirementBossName" width="100" align="center">
          <template #="{ row }">
            <span>{{ row.requirementBossName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="需求创建人" prop="requirementCreateName" width="100" align="center">
          <template #="{ row }">
            <span>{{ row.requirementCreateName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="负责测试" prop="contactTestNames" width="160" align="center">
          <template #="{ row }">
            <span>{{ row.contactTestNames }}</span>
          </template>
        </el-table-column>
        <el-table-column label="项目经理" prop="requirementManagerName" width="100" align="center">
          <template #="{ row }">
            <span>{{ row.requirementManagerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="需求状态" prop="requirmentFatherStatus" width="100" align="center">
          <template #="{ row }">
            <span :style="{
              color: fatherStatus(row.requirmentFatherStatus).bgColor,
            }">{{ fatherStatus(row.requirmentFatherStatus).text }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" align="center">
          <template #default="{ row }">
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus <= 1 && (userAuthId == 333 || userAuthId == 444)"
              size="small" type="primary" @click="dingdingOnlineClick(row.itemRequirementId)">
              通知技术负责人上线评审
            </el-button>
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus <= 1 && userAuthId != 333 && userAuthId != 444"
              size="small" type="primary" :disabled="true">
              等待项目经理通知上线评审
            </el-button>
            
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 2 && (userAuthId == 333 || userAuthId == 444)"
              size="small" type="primary" disabled>
              等待技术负责人参与选择上线评审人
            </el-button>
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 2 && (userAuthId == 111 || userAuthId == 555 || userAuthId == 888 || userAuthId == 999)"
              size="small" type="primary" @click="handleSelectOnlineUsersDialog(row.itemRequirementId)">
              选择参与上线评审人
            </el-button>
            <el-button style="display:inline;"
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 3" size="small"
              type="primary" disabled>
              等待参与人填写负责内容
            </el-button>
            
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 4 && (userAuthId == 333 || userAuthId == 444)"
              size="small" type="primary" @click="handleOpenDialog(row)">
              发起上线评审
            </el-button>

            <el-button
              v-if="row.requirmentFatherStatus === 7 && (userAuthId == 333 || userAuthId == 444) && row.guessTime17 == null"
              size="small" type="primary" @click="handleOpenTimeDialog(row)">
              今天上线
            </el-button>

            <el-button
              v-if="row.requirmentFatherStatus === 7 && (userAuthId == 333 || userAuthId == 444) && row.guessTime17 !== null"
              size="small" type="primary" @click="handleOpenTimeDialog(row)" disabled>
              今天上线
            </el-button>

            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 4 && (userAuthId != 333 && userAuthId != 444)"
              size="small" type="primary" disabled>
              等待项目经理发起上线评审
            </el-button>
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 5 && (userAuthId == 333 || userAuthId == 444)"
              size="small" type="primary" @click="handleCheckOpenDialog(row.itemRequirementId)">
              核实上线负责任务
            </el-button>
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 5 && (userAuthId != 333 && userAuthId != 444)"
              size="small" type="primary" disabled>
              上线评审进行中
            </el-button>
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 6 && (userAuthId == 333 || userAuthId == 444)"
              size="small" type="primary" @click="handleWriteMsgOpenDialog(row.itemRequirementId)">
              填写上线评审会议纪要
            </el-button>
            <el-button
              v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus === 6 && (userAuthId != 333 && userAuthId != 444)"
              size="small" type="primary" disabled>
              项目经理填写上线评审会议纪要中
            </el-button>
            <el-button v-if="row.requirmentFatherStatus === 6 && row.itemRequirementReviewStatus >=3" size="small"
              @click="handleViewsDialog(row.itemRequirementId)" type="primary">
              查看进度
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>


  <!-- 今天上线时间 -->
  <el-dialog v-model="dialogOnlineTimeVisible" title="今天上线时间" :close-on-click-modal="false" width="600" style="margin-top: 180px;"
    @close="handleColseDialog" @closed="handleColseDialog">
    <el-form label-position="right" label-width="160px" ref="showNoTipFormRef" v-model="onlineForm">
      <el-form-item label=" 上线时间：" prop="offlineSubmitBareTime">
        <el-time-picker v-model="onlineForm.offlineSubmitBareTime" type="datetime" placeholder="请选择上线时间" />
      </el-form-item>
      <el-form-item>
        <div class="dialog-footer" style="width: 100%; display: flex;justify-content: right;">
          <el-button @click="handleColseDialog">取消</el-button>
          <el-button type="primary" @click="postOnlineClick()"> 确定 </el-button>
        </div>
      </el-form-item>
    </el-form>
  </el-dialog>

  <!-- 上线评审模态框 -->
  <el-dialog v-model="dialogOnlineVisible" title="上线评审" width="600" style="margin-top: 180px;"
    @close="handleColseDialog" @closed="handleColseDialog">
    <el-form label-position="right" label-width="160px" ref="showNoTipFormRef" v-model="onlineForm">
      <el-form-item label=" 上线评审时间：" prop="offlineSubmitBareTime">
        <el-date-picker v-model="onlineForm.offlineSubmitBareTime" type="datetime" placeholder="请选择上线评审时间" />
      </el-form-item>
      <el-form-item>
        <!-- <template #footer> -->
        <div class="dialog-footer" style="width: 100%; display: flex;justify-content: right;">
          <el-button @click="handleColseDialog">取消</el-button>
          <el-button type="primary" @click="pushOnlineClick()"> 通过 </el-button>
        </div>
        <!-- </template> -->
      </el-form-item>
    </el-form>
  </el-dialog>

  <!-- 上线评审会议纪要 -->
  <el-dialog v-model="dialogWriteOnlineVisible" title="上线评审会议纪要" :close-on-click-modal="false" width="1000" style="margin-top: 180px;"
    @close="handleColseWriteOnlineDialog" @closed="handleColseWriteOnlineDialog">
    <el-form label-position="right" label-width="160px" v-model="onlineWirteMsgForm">
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">会议纪要：</p>
      </div>
      <el-input v-model="onlineWirteMsgForm.offlineSubmitBareMsg"
        style="width: 900px;margin-bottom: 20px;margin-right: 20px;" :rows="12" type="textarea" placeholder="请输入会议纪要内容">
      </el-input>
      <el-form-item>
        <!-- <template #footer> -->
        <div class="dialog-footer" style="width: 100%;margin-right: 8%; display: flex;justify-content: right;">
          <el-button type="primary" @click="dingdingWriteOnlineMsgClick()"> 提交 </el-button>
        </div>
        <!-- </template> -->
      </el-form-item>
    </el-form>
  </el-dialog>

  <!-- 选择上线参与人 -->
  <el-dialog v-model="dialogSelectOnlineUsersVisible" title="上线评审参与人确认" width="600" style="margin-top: 180px;"
    @close="handleColseSelectOnlineUsersDialog" @closed="handleColseSelectOnlineUsersDialog">
    <el-form label-position="right" label-width="60px" :model="onlineUsersForm">
      <el-form-item class="search-wrap-item" label="研发：">
        <el-select class="search-select" filterable v-model="onlineUsersForm.devesSelect" placeholder="选择研发"
          size="default" multiple clearable style="min-width: 200px; max-height: 50px; font-weight: normal;">
          <el-option v-for="(item, index) in onlineUsersForm.deves" :key="item.uuid" :label="item.userName"
            :value="item.uuid"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item class="search-wrap-item" label="运维：">
        <el-select class="search-select" filterable v-model="onlineUsersForm.msSelect" placeholder="选择运维" size="default"
          multiple clearable style="min-width: 200px; max-height: 50px; font-weight: normal;">
          <el-option v-for="(item, index) in onlineUsersForm.ms" :key="item.uuid" :label="item.userName"
            :value="item.uuid"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item class="search-wrap-item" label="测试：">
        <el-select class="search-select" filterable v-model="onlineUsersForm.tsSelect" placeholder="选择测试" size="default"
          multiple clearable style="min-width: 200px; max-height: 50px; font-weight: normal;">
          <el-option v-for="(item, index) in onlineUsersForm.ts" :key="item.uuid" :label="item.userName"
            :value="item.uuid"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <div class="dialog-footer" style="width: 100%; display: flex;justify-content: right;">
          <el-button type="primary" @click="handleSelectOnlineUsersClick()"> 确定 </el-button>
        </div>
      </el-form-item>
    </el-form>
</el-dialog>

  <!-- 核实上线评审模态框 -->
  <el-dialog v-model="dialogCheckOnlineVisible" :close-on-click-modal="false" title="上线各自负责任务" width="1000" style="margin-top: 180px;"
    @close="handleColseOnlineDialog" @closed="handleColseOnlineDialog">
    <el-form label-position="right" label-width="160px" v-model="allbearUsers">
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">研发：</p>
      </div>
      <div v-for="(user, index) in allbearUsers" :key="index">
        <el-input v-if="user.bearType == 1" v-model="user.bearUserName" style="width: 100px;margin-bottom: 20px;"
          disabled placeholder="Please input">
        </el-input>
        <el-input v-if="user.bearType == 1" v-model="user.bearContent"
          style="width: 700px;margin-bottom: 20px;margin-right: 20px;" :rows="1" type="textarea" placeholder="请输入负责内容">
        </el-input>
      </div>
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">运维：</p>
      </div>
      <div v-for="(user, index) in allbearUsers" :key="index">
        <el-input v-if="user.bearType == 2" v-model="user.bearUserName" style="width: 100px;margin-bottom: 20px;"
          disabled placeholder="Please input">
        </el-input>
        <el-input v-if="user.bearType == 2" v-model="user.bearContent"
          style="width: 700px;margin-bottom: 20px;margin-right: 20px;" :rows="1" type="textarea" placeholder="请输入负责内容">
        </el-input>
      </div>
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">测试：</p>
      </div>
      <div v-for="(user, index) in allbearUsers" :key="index">
        <el-input v-if="user.bearType == 3" v-model="user.bearUserName" style="width: 100px;margin-bottom: 20px;"
          disabled placeholder="Please input">
        </el-input>
        <el-input v-if="user.bearType == 3" v-model="user.bearContent"
          style="width: 700px;margin-bottom: 20px;margin-right: 20px;" :rows="1" type="textarea" placeholder="请输入负责内容">
        </el-input>
      </div>
      <el-form-item>
        <!-- <template #footer> -->
        <div class="dialog-footer" style="width: 100%; display: flex;justify-content: right;">
          <el-button type="primary" @click="saveBareUsersMsgClick()"> 评审完成 </el-button>
        </div>
        <!-- </template> -->
      </el-form-item>
    </el-form>
  </el-dialog>

  <!-- 查看上线负责内容填写进度 -->
  <el-dialog v-model="dialogCheckDisOnlineVisible" :close-on-click-modal="false" title="上线负责任务填写进度" width="1000" style="margin-top: 180px;"
    @close="handleColseDisOnlineDialog" @closed="handleColseDisOnlineDialog">
    <el-form label-position="right" label-width="160px" v-model="allbearUsers">
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">研发：</p>
      </div>
      <div v-for="(user, index) in allbearUsers" :key="index">
        <el-input v-if="user.bearType == 1" v-model="user.bearUserName" style="width: 100px;margin-bottom: 20px;"
          disabled placeholder="Please input">
        </el-input>
        <el-input v-if="user.bearType == 1" v-model="user.bearContent"
          style="width: 700px;margin-bottom: 20px;margin-right: 20px;" :rows="1" type="textarea" disabled>
        </el-input>
        <el-button v-if="user.bearType == 1 && user.bearContent == '' && (userAuthId ==333||userAuthId ==444||userAuthId ==555||userAuthId ==888||userAuthId ==999)" type="primary"
          style="margin-bottom: 20px;margin-right: 20px;" @click="dingDingClick(user.bearId)"> 提醒他 </el-button>
      </div>
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">运维：</p>
      </div>
      <div v-for="(user, index) in allbearUsers" :key="index">
        <el-input v-if="user.bearType == 2" v-model="user.bearUserName" style="width: 100px;margin-bottom: 20px;"
          disabled placeholder="Please input">
        </el-input>
        <el-input v-if="user.bearType == 2" v-model="user.bearContent"
          style="width: 700px;margin-bottom: 20px;margin-right: 20px;" :rows="1" type="textarea" disabled>
        </el-input>
        <el-button v-if="user.bearType == 2 && user.bearContent == '' && (userAuthId ==333||userAuthId ==444||userAuthId ==555||userAuthId ==888||userAuthId ==999)" type="primary"
          style="margin-bottom: 20px;margin-right: 20px;" @click="dingDingClick(user.bearId)"> 提醒他 </el-button>
      </div>
      <div class="dialog-footer" style="width: 100%; display: flex;justify-content: left;">
        <p style="font-weight: bold;margin-bottom: 20px;">测试：</p>
      </div>
      <div v-for="(user, index) in allbearUsers" :key="index">
        <el-input v-if="user.bearType == 3" v-model="user.bearUserName" style="width: 100px;margin-bottom: 20px;"
          disabled placeholder="Please input">
        </el-input>
        <el-input v-if="user.bearType == 3" v-model="user.bearContent"
          style="width: 700px;margin-bottom: 20px;margin-right: 20px;" :rows="1" type="textarea" disabled>
        </el-input>
        <el-button v-if="user.bearType == 3 && user.bearContent == '' && (userAuthId ==333||userAuthId ==444||userAuthId ==555||userAuthId ==888||userAuthId ==999)" type="primary"
          style="margin-bottom: 20px;margin-right: 20px;" @click="dingDingClick(user.bearId)"> 提醒他 </el-button>
      </div>
    </el-form>
  </el-dialog>

   <!-- 需求详情弹窗 -->
   <el-dialog v-if="dialogInfoVisible" style="width: 1200px;" :close-on-click-modal="false" v-model="dialogInfoVisible" @close="handleCloseDialog" @closed="handleCloseDialog">
        <CommonRequirementInfoVue :isRequirementID="isRequirementID" :clearData="clearData"></CommonRequirementInfoVue>
    </el-dialog>
</template>

<script setup lang='ts'>
import { ref, onMounted, reactive, computed } from 'vue';
import { ElMessage, ElMessageBox, ElNotification, FormInstance, } from "element-plus";
import { fatherStatus, tableTimeDateMsgTow } from "@/utils/utils";
import { useRouter } from "vue-router";
import CommonRequirementInfoVue from "../comomRequirementInfo.vue";
import { postUploadFile } from "@/api/common/index";
import {
  PostManagerRequirement, //获取项目经理管理项目的所有需求
  GetManagerOnline,
  PostOfflineBearContent,
  PostOfflineBearContentMsg,
  GetGetBareUsersMsgs,//获取上线评审需求各自负责的内容
  PostUpdateBareUsersMsgs,//更新上线评审需求各自负责的内容
  GetOnlineUsers,//获取上线参与人列表
  PostSelectBareUsers,// 技术负责人分配参与上线人员
  DingDingOnlineWriteBearContents,//提醒填写上线负责任务
  PostSureOnline,// 提交今天上线时间
  GetMyBareMsg,
} from "@/api/newDemands/index";



/* 参数 */
let router = useRouter();
const loading = ref(false);
const searchFormData = ref({
  projectTitle: "",
  beginTime: null,
  endTime: null,
  requirementStatus: 6,
});//搜索关键字


const userAuthId = ref<any>(null);//当前用户权限id
userAuthId.value = localStorage.getItem("authorityId");
const dialogInfoVisible = ref(false);//查看需求弹窗
const isRequirementID = ref<any>(null);// 当前查看需求id
const clearData = ref(false);//控制是否清空子组件数据
const dialogOnlineVisible = ref(false); //上线评审模态框
const dialogCheckOnlineVisible = ref(false); //核实上线评审内容模态框
const dialogCheckDisOnlineVisible = ref(false); //查看上线评审内容模态框
const dialogWriteOnlineVisible = ref(false); //上线评审会议纪要模态框
const dialogSelectOnlineUsersVisible = ref(false); //选择上线参与人模态框
const dialogOnlineTimeVisible = ref(false); //选择今天上线弹窗
const allRequirements = ref<any>([]); // 所有待上线评审需求
const allbearUsers = ref<any>([]); // 各自负责的上线任务
const requirementStatuss = ref<any>([
  { id: 1, typeName: "待分配" },
  { id: 2, typeName: "待开发" },
  { id: 3, typeName: "开发中" },
  { id: 4, typeName: "详细设计确认中" },
  { id: 5, typeName: "测试中" },
  { id: 6, typeName: "待上线评审" },
  { id: 7, typeName: "待上线" },
  { id: 8, typeName: "已上线" },
  { id: 9, typeName: "已关闭" },
]); // 所有需求状态

// 提交表单数据
const onlineForm = ref<any>({
  requirementId: null,
  offlineSubmitBareTime: null,
});
// 会议纪要表单数据
const onlineWirteMsgForm = ref<any>({
  requirementId: null,
  offlineSubmitBareMsg: null,
});
// 选择参与上线评审人数据
const onlineUsersForm = ref<any>({
  requirementId: null,
  deves: null,
  ms: null,
  ts: null,
});
const postOnlineUsersForm = ref<any>({
  requirementId: null,
  deves: [],
  ms: [],
  ts: [],
});


// 查看填写进度
const handleViewsDialog = (id: number) => {
  postOnlineUsersForm.value.requirementId = id
  loading.value = true
  getGetBareUsersMsgs(id)
  dialogCheckDisOnlineVisible.value = true;
}


// 开启上线评审模态框方法
const handleOpenDialog = (val: any) => {
  onlineForm.value.requirementId = val.itemRequirementId;
  dialogOnlineVisible.value = true;
};
// 开启今天上线弹窗
const handleOpenTimeDialog = (val: any) => {
  onlineForm.value.requirementId = val.itemRequirementId;
  dialogOnlineTimeVisible.value = true;
};
// 核实上线评审内容
const handleCheckOpenDialog = (id: number) => {
  onlineForm.value.requirementId = id;
  loading.value = true
  getGetBareUsersMsgs(id)
  dialogCheckOnlineVisible.value = true;
};
// 项目经理填写上线评审会议纪要
const handleWriteMsgOpenDialog = (id: number) => {
  onlineWirteMsgForm.value.requirementId = id;
  loading.value = true
  // dingdingWriteOnlineMsgClick(id)
  dialogWriteOnlineVisible.value = true;
};
// 选择上线参与人
const handleSelectOnlineUsersDialog = (id: number) => {
  loading.value = true
  handleGetOnlineUsersClick(id)
  dialogSelectOnlineUsersVisible.value = true;
  console.log(onlineUsersForm.value)
};
// 取消模态框
const handleColseDialog = () => {
  loading.value = false
  dialogOnlineVisible.value = false;
  dialogOnlineTimeVisible.value = false;
};
const handleColseOnlineDialog = () => {
  loading.value = false
  dialogOnlineVisible.value = false;
};
const handleColseDisOnlineDialog = () => {
  loading.value = false
  dialogCheckOnlineVisible.value = false;
};
const handleColseWriteOnlineDialog = () => {
  loading.value = false
  dialogWriteOnlineVisible.value = false;
};
const handleColseSelectOnlineUsersDialog = () => {
  loading.value = false
  dialogSelectOnlineUsersVisible.value = false;
};



//选择上线参与人后提交
const handleSelectOnlineUsersClick = async () => {
  postOnlineUsersForm.value.requirementId = onlineUsersForm.value.requirementId;
  postOnlineUsersForm.value.deves = onlineUsersForm.value.devesSelect;
  postOnlineUsersForm.value.ms = onlineUsersForm.value.msSelect;
  postOnlineUsersForm.value.ts = onlineUsersForm.value.tsSelect;
  const { data } = await PostSelectBareUsers(postOnlineUsersForm.value);
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    dialogSelectOnlineUsersVisible.value = false;
    getAllRequirements();
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
}
//获取上线参与人列表
const handleGetOnlineUsersClick = async (id: number) => {
  const { data } = await GetOnlineUsers(id);
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    onlineUsersForm.value = {
      ts: data.data.Ts?.map((item: any) => ({
        userName: item.userName,
        uuid: item.uuid,
      })),
      ms: data.data.Ms?.map((item: any) => ({
        userName: item.userName,
        uuid: item.uuid,
      })),
      deves: data.data.Deves?.map((item: any) => ({
        userName: item.userName,
        uuid: item.uuid,
      })),
    };
    onlineUsersForm.value.devesSelect = [];
    onlineUsersForm.value.msSelect = [];
    onlineUsersForm.value.tsSelect = [];
    onlineUsersForm.value.requirementId = id;
    console.log(onlineUsersForm.value);
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
}
//提醒他
const dingDingClick = async (id: number) => {
  const { data } = await DingDingOnlineWriteBearContents(id);
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
}

//核实上线评审内容
const getGetBareUsersMsgs = async (id: number) => {
  const { data } = await GetGetBareUsersMsgs(id);
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    console.log(data)
    allbearUsers.value = data.data.map((item: any) => {
      return {
        bearUserName: item.bearUserName,
        bearContent: item.bearContent,
        bearType: item.bearType,
        bearId: item.ID,
      }
    })

    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
}


// 查看需求详情
const handleRowClick = async (id: number) => {
  console.log("查看需求:", id);
  dialogInfoVisible.value = true;
  isRequirementID.value = id;
};

// 关闭查看需求弹窗
const handleCloseDialog = () => {
  dialogInfoVisible.value =false;
  clearData.value = true;
};

// 今天上线时间
const postOnlineClick = async () => {
  console.log(onlineForm.value.offlineSubmitBareTime)

  const {data} = await PostSureOnline({
    requirementId: onlineForm.value.requirementId,
    offlineSubmitBareTime: tableTimeDateMsgTow(onlineForm.value.offlineSubmitBareTime),
  });
  if(data.code === 200) {
    ElMessage.success(data.msg);
    handleColseDialog();
    loading.value = true;
    await getAllRequirements();
    loading.value = false;
    return;
  } else {
    ElMessage.error(data.msg);
    throw console.error(data.msg);
  }
};

// 项目经理发起上线评审
const pushOnlineClick = async () => {
  loading.value = true;
  const { data } = await PostOfflineBearContent({
    requirementId: onlineForm.value.requirementId,
    offlineSubmitBareTime: onlineForm.value.offlineSubmitBareTime,
  })
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    handleColseDialog();
    getAllRequirements();
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    handleColseDialog()
    return;
  }
};
// 通知技术负责人上线评审
const dingdingOnlineClick = async (id: number) => {
  loading.value = true;
  const { data } = await GetManagerOnline(id)
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    getAllRequirements();
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
};
// 项目经理填写上线评审会议纪要
const dingdingWriteOnlineMsgClick = async () => {
  loading.value = true;
  const { data } = await PostOfflineBearContentMsg(onlineWirteMsgForm.value)
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    dialogWriteOnlineVisible.value = false;
    getAllRequirements();
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
};

// 更新每人负责的内容
const saveBareUsersMsgClick = async () => {
  await ElMessageBox.confirm("上线评审完成，完成状态变更！", "确定", {
    cancelButtonText: "取消",
    confirmButtonText: "确定",
    type: "warning",
  }).then(async () => {
    PostUpdateBareUsersMsgs(allbearUsers.value)
    getAllRequirements()//刷新数据
  });



  const { data } = await PostUpdateBareUsersMsgs(allbearUsers.value);
  if (data.code === 200 && data.data !== null) {
    ElMessage.success(data.msg);
    loading.value = false;
    dialogCheckOnlineVisible.value = false
    getAllRequirements()
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }



}



// TODO 获取所有待上线评审需求
const getAllRequirements = async () => {
  loading.value = true;
  const { data } = await PostManagerRequirement({
    projectTitle: searchFormData.value.projectTitle,
    beginTime:
      searchFormData.value.beginTime,
    endTime:
      searchFormData.value.endTime,
    requirementStatus: searchFormData.value.requirementStatus
  });

  if (data.code === 200 && data.data !== null) {
    allRequirements.value = data.data
      .map((item: any) => {
        return {
          itemRequirementId: item.ID,//需求id
          itemRequirementName: item.requirementName,  //需求名称
          requirementBossName: item.requirementBossName,//技术负责人
          requirementManagerName: item.requirementManagerName,//项目经理名称
          requirementCreateName: item.requirementCreateName,//需求创建人
          contactTestNames: item.contactTestNames,//负责测试
          requirmentFatherStatus: item.requirmentFatherStatus,//需求当前状态
          itemRequirementReviewStatus: item.itemRequirementReviewStatus,//当前上线评审状态
          guessTime17: item.guessTime17,//上线时间
        };
      });

    console.log("待审核需求：", allRequirements.value);
    ElMessage.success(data.msg);
    loading.value = false;
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    return;
  }
};



// 页面初始化调用接口
onMounted(async () => {
  getAllRequirements()
});

</script>
<style lang='scss' scoped>
.content-container {
  background-color: white;
  display: flex;
  flex-direction: column;
  padding: 10px;
  overflow-y: auto;

  // TODO 搜索区域
  .search-wrap {
    width: 100%;
    height: 40px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #dcdfe6;

    .search-wrap-item {
      margin-right: 20px;
      min-width: 200px;
      font-weight: bold;
      font-size: 24px;
      font-family: Arial, Helvetica, sans-serif;
      color: #000;
    }
  };

  .table-requirement-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .table-requirement-name:hover {
    cursor: pointer;
    color: #409EFF;
  }


}
</style>